﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Simple.HttpServer {
    public static class Extensions {

        public static string XmlSerialize<TObject>(this TObject value) {
            var xs = new XmlSerializer(typeof(TObject));
            var ms = new MemoryStream();
            xs.Serialize(ms, value);
            var result = Encoding.UTF8.GetString(ms.ToArray());
            return result;
        }

        public static TResult XmlDeserialize<TResult>(this string value) where TResult : class {
            var sr = new StringReader(value);
            var xs = new XmlSerializer(typeof(TResult));
            TResult result = xs.Deserialize(sr) as TResult;
            return result;
        }
    }
}
